package com.cyn.controller;

import com.cyn.entity.SysUser;
import com.cyn.service.SuccessKilledService;
import com.cyn.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("successKilled")
public class SuccessKilledController {


    @Autowired
    private SuccessKilledService successKilledService;

    @Autowired
    private SysUserService sysUserService;

    @GetMapping("skilled")
    public Map<String,Object> insert(String userPhone,String projectId) {

        Map<String,Object> params = new HashMap<>();
        try {
            params = successKilledService.skilled(userPhone,projectId);
        } catch (Exception e) {
            return params;
        }
        return params;
    }

    @GetMapping("skilledByRedisLock")
    public Map<String,Object> skilledByRedisLock(String userPhone,String projectId,String index) {

        Map<String,Object> params = new HashMap<>();
        try {
            params = successKilledService.skilledByRedisLock(userPhone,projectId,index);
        } catch (Exception e) {
            e.printStackTrace();
            return params;
        }
        return params;
    }

    @GetMapping("inserUser")
    public Map<String,Object> inserUser(String index) {
        Map<String,Object> params = new HashMap<>();
        try {
            SysUser sysUser = new SysUser();
            String[] tmp = index.split("_");
            sysUser.setUserName(tmp[0]);
            sysUser.setLoginName(tmp[1]);
            sysUser.setCreateTime(new Date());
            sysUser.setUpdateTime(new Date());
            sysUser.setSex(1);
            sysUser.setStatus(1);
            sysUserService.insert(sysUser);
            params.put("index",index);
        } catch (Exception e) {
            e.printStackTrace();
            return params;
        }
        return params;
    }

}
